<?php

include($_SERVER['DOCUMENT_ROOT'] . '/fatec-si/authenticate/' . 'Authenticator.php');
class LoginController
{

	public function logar(array $var){
		header("Content-Type: text/html; charset=ISO-8859-1",true);
		$result = Authenticator::authenticate($var['user'],$var['password']);
		$status = true;
		$url = "";
		$liberado = 1;
		if ($result){
			$url = SITE_ROOT."/sistema/".$_SESSION['user']->tipo_usuario_nome.".html";
			$status = true;
			if ($_SESSION['user']->status == 0){
				$liberado = 0;
			}
		}else{
			$url = SITE_ROOT."/error.html";
			$status = false;
			$liberado = 0;
		}

		$result = array(
	        'url' => $url,
	        'status' => $status,
	        'liberado' => $liberado
		);
		echo json_encode($result);
			
	}


	public function logout(array $var){
		session_destroy();
		$redirect = $_SERVER['DOCUMENT_ROOT']."/fatec-si/".$var["url"];
		header("location:$redirect");
	}
}
